﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLKS
{
    public partial class frthemnv : Form
    {
        public frthemnv()
        {
            InitializeComponent();
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnthemnv_Click(object sender, EventArgs e)
        {
            if (txtTenNV.Text == "" && txtDiaChi.Text == "")
            {
                MessageBox.Show("Ban chua nhap het cac o trong.");
            }
            else
            {
                try
                {
                    DTO.CNHANVIEN nv = new DTO.CNHANVIEN();
                    nv.HoTen = txtTenNV.Text;
                    nv.NgaySinh = dtNTNS.Value;
                    TimeSpan diff = DateTime.Now - dtNTNS.Value;
                    nv.Tuoi = (int)(diff.Days / 365);
                    nv.DiaChi = txtDiaChi.Text;
                    nv.MaLoaiNhanVien = "nv";

                    if (!(BUS.XuLyNhanVien.ThemNhanVien(nv)))
                    {
                        MessageBox.Show("Co loi xay ra. Kiem tra lai file CSDL");
                    }

                    txtDiaChi.Text = "";
                    txtTenNV.Text = "";
                }
                catch (System.Exception )
                {
                    MessageBox.Show("Kiem tra lai thong tin nhap.");
                }
                this.Close();
            }
        }

        private void frthemnv_Load(object sender, EventArgs e)
        {
        }

    }
}
